const {ccclass, property, menu , disallowMultiple} = cc._decorator;

@ccclass
@menu('工具组件/跟随')
export default class Follow extends cc.Component{
    @property({type:cc.Node,displayName:"跟随者"})
    public target : cc.Node = null;
    @property({displayName:"是否老版"})
    private old:boolean = true;

    private offset : cc.Vec2 = null;
    public set Target(value){
        this.target = value;
        this.offset = this.target.getPosition().sub(this.node.getPosition());
    }

    onLoad(){
        if(!this.target){return;}
        this.offset = this.target.getPosition().sub(this.node.getPosition());
    }

    update(){
        if(!this.target){return;}
        if(this.old){
            this.node.setPosition(this.target.getPosition().add(this.offset));//ToFixed
        }else{
            this.node.setPosition(this.target.getPosition().sub(this.offset));
        }
    }
}